class RequeteSQL:
    
    " Cette fonction elle est propre a sqlLite"
    def sqlStructureDB(self,):
        return "SELECT name,sql FROM sqlite_master; "
            
    def sqlInsert(self,table,valeurs, nomColonne):
        monsql="INSERT INTO "+table+ "("
        for nom in nomColonne:
            monsql = monsql  + nom[0]+ ", "
        monsql = monsql[:-2] 
        monsql = monsql + ") values ("
        for i in valeurs:
            monsql=monsql+ "'" +i+"'" + ", "
        monsql=monsql[:-2]+") "
        return monsql
    
    def sqlUpdate(self,table,col,valeur):
        pass
    
    def sqlDelete(self,enregistrement):
        if enregistrement == "*":
            "DELETE FROM choses where nom<>NULL"
    
    def sqlCreate(self,nomTable,cols):
        monsql="CREATE TABLE "+nomTable+" ("
        for i in cols:
            monsql=monsql+i[0]+" "+i[1]+", "
        monsql=monsql[:-2]+")"
        return monsql
    
    def sqlAlter(self,table,col,sorte, action):
        monsql="ALTER TABLE "+table+" "+action+" "+col +" "+sorte+";"
        return monsql
        
    def sqlDrop(self,table):
        monsql="DROP TABLE "+table+""
        return monsql
    """
    Construction du de la clause where du cote client
    table= 'Emp, Dept'
    [' x=y ',' a and b ',' c or d ',' between z and t ' ]
    group='NoDept'
    """
    def sqlWhere(self,tables, cols=None,ou=None, group=None):
        if cols==None:
            monsql="SELECT * FROM " + tables
            if ou!=None:
                monsql+= " WHERE "
                for where in ou:
                    monsql=monsql + where
            if group!=None:
                monsql+=' GROUP BY '+group
            else:
                pass
        else:
            monsql="SELECT"
            for col in cols:
                monsql+= ' '+ col + ', '
            monsql=monsql[:-2]
            monsql = monsql + " from " + tables + " "
            if ou!=None:
                monsql+= " WHERE "
                for where in ou:
                    monsql=monsql + where
            if group!=None:
                monsql+=' GROUP BY '+group
        return monsql
    
    def sqlSelect(self, table, cols="*",ou=[]):
        monsql="SELECT "+cols+" from "+table 
        if ou:
            monsql=monsql+" WHERE "+ou[0]+ou[1]+ou[2]
        monsql=monsql+""
        return monsql
    
    def sqlColumn(self, nomTable):
        monsql = self.sqlSelect( 'USER_CONS_COLUMNS', 'column_name', ['table_name', '=', "'" + nomTable+"'"])
        return monsql
